package com.tj.test.sys.service.impl;

import com.tj.test.sys.dao.TeacherMapper;
import com.tj.test.sys.po.PST;
import com.tj.test.sys.po.Teacher;
import com.tj.test.sys.service.ITeacherService;
import com.tj.test.sys.tool.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class TeacherService implements ITeacherService {
    @Autowired
    private TeacherMapper mapper;

    @Override
    //查询所有教师信息
    public List<Teacher> selectAllTeacher() {
        List<Teacher> list=new ArrayList<>();

        if (!mapper.selectAllTeacher().isEmpty()){
            list=mapper.selectAllTeacher();
        }
        return list;
    }

    @Override
    //插入教师信息
    public int insertTeacher(PST teacher) {
        int temp=0;
        /* 业务判断
         * （1）人员名称不能重复
         * （2）增加人员之前先查询*/
        try{
            //temp=mapper.selectTeacherById(teacher);
            if (temp<1){
               // temp=mapper.insertTeacher(teacher);
            }else{
               return temp;
            }
        }catch (Exception e){
              return -2;
        }
               return temp;
    }

    @Override
    //删除教师信息
    public int deleteTeacher( PST teacher) {
        int temp=0;
        try{
            temp=mapper.selectTeacherById(teacher);
            if (temp>0){
                temp=mapper.deleteTeacher(teacher);
            }else{
               return -2;
            }
        }catch (Exception e){
            return -1;
        }
        return temp;
    }

    @Override
    //修改教师信息
    public int updateTeacher(PST teacher) {
        int temp=0;
        try{
            temp=mapper.selectTeacherById(teacher);
            if (temp<1){
                temp=mapper.updateTeacher(teacher);
            }else{
                return temp;
            }
        }catch (Exception e){
            System.out.println(e.getStackTrace());
            return -1;
        }
        return temp;
    }
}
